package data

import (
	"context"
	"digitalhuman/models"
)

func NewTextAudioData(data *Data, x *XunFei) *TextAudioData {
	return &TextAudioData{
		Data: data,
		x:    x,
	}
}

type TextAudioData struct {
	Data *Data
	x    *XunFei
}

func (u TextAudioData) Create(ctx context.Context, s *models.TextAudio) (*models.TextAudio, error) {
	u.Data.Db.Create(s)

	return s, nil
}

func (u TextAudioData) Update(ctx context.Context, s *models.TextAudio) (*models.TextAudio, error) {
	u.Data.Db.Updates(s)

	return s, nil
}

func (u TextAudioData) UpdateState(ctx context.Context, id int, status int) (bool, error) {
	u.Data.Db.Model(&TextAudioData{}).Update("status", status).Where("id = ?", id)

	return true, nil
}

func (u TextAudioData) FindBySectionId(background context.Context, secId int) *models.TextAudio {
	var ta *models.TextAudio
	result := u.Data.Db.Where("storyboard_section_id = ?", secId).First(&ta)
	if result.Error != nil {
		return nil
	}
	return ta
}

func (u TextAudioData) FindByStoryId(background context.Context, id int) *models.TextAudio {
	var ta *models.TextAudio
	result := u.Data.Db.Where("storyboard_id = ?", id).First(&ta)
	if result.Error != nil {
		return nil
	}
	return ta
}
